//package com.plian.system.controller.hr.abroad;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.Func;
//import com.plian.Tools.StringPool;
//import com.plian.Tools.TokenUtil;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.config.Resubmit;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.dto.hr.abroad.AbroadDeclarationDTO;
//import com.plian.system.entity.hr.abroad.AbroadDeclaration;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.search.TokenSearch;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.hr.abroad.IAbroadDeclarationService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.hr.abroad.AbroadDeclarationVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.wrapper.hr.abroad.AbroadDeclarationWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.validation.Valid;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 因公出国（境）计划申报管理 控制器
// *
// * @author gangan
// * @since 2019-12-02
// */
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/abroaddeclaration")
//public class AbroadDeclarationController extends BaseController {
//
//	private IAbroadDeclarationService abroadDeclarationService;
//
//	private FormWorkflowService formWorkflowService;
//
//    private IFormCodeService formCodeService;
//
//    private AbroadDeclarationWrapper abroadDeclarationWrapper;
//
//    /**
//    * 详情
//    */
//	@PostMapping("/detail")
//	public R<AbroadDeclarationVO> detail(@Valid @RequestBody AbroadDeclaration abroadDeclaration) {
//        AbroadDeclaration detail = abroadDeclarationService.getOne(Condition.getQueryWrapper(abroadDeclaration));
//        AbroadDeclarationVO abroadDeclarationVO = abroadDeclarationWrapper.entityToVO(detail);
//        return R.data(abroadDeclarationVO);
//	}
//
//	/**
//	* 分页 因公出国（境）计划申报管理
//	*/
//	@PostMapping("/list")
//	public ListResult<AbroadDeclarationVO> list(@Valid @RequestBody Query query) {
//		if(query.getAscs()==null&&query.getDescs()==null){
//            query.setDescs("create_time");
//		}
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<AbroadDeclaration> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new AbroadDeclaration()), entityList
//        );
//        TokenSearch<AbroadDeclaration> tokenSearch = new TokenSearch<>();
//        tokenSearch.addTokenQuery(queryWrapper, query);
//
//		IPage<AbroadDeclaration> pages = abroadDeclarationService.page(Condition.getPage(query), queryWrapper);
//        List<AbroadDeclarationVO> abroadDeclarationVOS = abroadDeclarationWrapper.entityToVO(pages.getRecords());
//        ListResult<AbroadDeclarationVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(abroadDeclarationVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//	}
//
//	/**
//	* 新增或修改 因公出国（境）计划申报管理
//	*/
//	@PostMapping("/submit")
//    @Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody AbroadDeclaration abroadDeclaration) {
//		if(abroadDeclaration.getId()==null){
//			abroadDeclaration.setVersion("1");
//            abroadDeclaration.setCode(formCodeService.getCode(FormTypeConstant.HR_ABROAD_DECLARATION_FORM));
//            abroadDeclaration.setFormType(String.valueOf(FormTypeConstant.HR_ABROAD_DECLARATION_FORM));
//		}
//        boolean result = abroadDeclarationService.saveOrUpdate(abroadDeclaration);
//        HashMap<String, Object> processVariable = new HashMap<>();
//        formWorkflowService.startProcessAndSimulate(String.valueOf(abroadDeclaration.getId()),abroadDeclaration.getFormType(),processVariable);
//
//        return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	* 删除 因公出国（境）计划申报管理
//	*/
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//        List<String> ids = (List<String>)pd.get("ids");
//		return abroadDeclarationService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//                ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	@PostMapping("/report")
//	public ObjResult reportTable(@Valid @RequestBody AbroadDeclarationDTO abroadDeclarationDTO) {
//        ObjResult objResult;
//        try {
//            ReportReturnVO reportReturnVO = abroadDeclarationService.report(abroadDeclarationDTO);
//            objResult = new ObjResult(CommonCode.SUCCESS);
//            if (Optional.ofNullable(reportReturnVO).isPresent()){
//                PageData pd = new PageData();
//                pd.put("grids", reportReturnVO.getGrids());
//                objResult.setPageData(pd);
//            }
//        }catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            objResult = new ObjResult(CommonCode.ERROR);
//            return objResult;
//        }
//
//        return objResult;
//
//	}
//
//    /**
//     * 分页 用于因公出国添加按钮获取上游单据
//     */
//    @PostMapping("/refList")
//    public ListResult<AbroadDeclarationVO> refList(@Valid @RequestBody Query query) {
//        if(query.getAscs()==null&&query.getDescs()==null){
//            query.setDescs("create_time");
//        }
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<AbroadDeclaration> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new AbroadDeclaration()), entityList
//        );
//        queryWrapper.lambda().eq(AbroadDeclaration::getDeclaringUnitId, TokenUtil.getTokenOrgId());
//        queryWrapper.lambda().eq(AbroadDeclaration::getStatus, FormStatusConstant.FINISH);
//        queryWrapper.lambda().eq(AbroadDeclaration::getTaskStatus, "058001");
//        IPage<AbroadDeclaration> pages = abroadDeclarationService.page(Condition.getPage(query), queryWrapper);
//        List<AbroadDeclarationVO> abroadDeclarationVOS = abroadDeclarationWrapper.entityToVO(pages.getRecords());
//        ListResult<AbroadDeclarationVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(abroadDeclarationVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//    }
//
//}
